import { watch, ref, reactive, toRefs } from "vue";
import axios from "axios";

function init() {
    let selectVal = ref("");
    let data = reactive({
        datalist: []
    });

    watch(selectVal, async (n, o) => {
        const res = await axios.get(`http://127.0.0.1:8888?name=${n}`);
        data.datalist = res.data;
    }, { immediate: true });

    return {
        selectVal,
        ...toRefs(data),
    };
}

export default init;